package com.ctshk.rpc.scenic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.scenic.dto.ScenicChargeDTO;
import com.ctshk.rpc.scenic.entity.ScenicProductTicket;
import com.ctshk.rpc.scenic.req.ScenicResourceTicketReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 门票票号 Mapper 接口
 * </p>
 *
 * @author wangcy
 * @since 2021-02-02
 */
public interface ScenicProductTicketMapper extends BaseMapper<ScenicProductTicket> {
    @Select("SELECT * from t_scenic_product_ticket \n" +
            "WHERE  strategy_id = #{resourceTicketReq.strategyId} and product_id \n" +
            " = #{resourceTicketReq.productId} and attr1_name = #{resourceTicketReq.attr1Name} \n" +
            " and attr2_name = #{resourceTicketReq.attr2Name} limit 1")
    ScenicProductTicket queruDetail(@Param("resourceTicketReq") ScenicResourceTicketReq resourceTicketReq);

    @Select("<script> SELECT * from t_scenic_product_ticket  \n" +
            "where is_deleted =0 \n" +
            "and `status`=1 \n" +
            "and  stock_id =#{stockid}   limit  ${number}  </script>")
    List<ScenicProductTicket> queryByStockId(@Param("stockid")Long strategyId,@Param("number") Integer number);


    @Select("SELECT sk.cost_price as costPrice, cs.exchange_rate as exchangeRate,cs.product_id as productid \n" +
            "from t_scenic_product_cost_strategy_spec_stock sk\n" +
            "INNER JOIN t_scenic_product_cost_strategy  cs on sk.strategy_id = cs .id  where sk.id = #{stockid}  limit 1")
    ScenicChargeDTO queryChargeByStockId(@Param("stockid")Long strategyId);

    @Update("UPDATE t_scenic_product_ticket \n" +
            "set supplier_ticket_number = #{supplierTicketNumber}  where id = #{id}")
    Integer updateSupplierTicketNumberByid(@Param("id") Long id, @Param("supplierTicketNumber")String supplierTicketNumber);

    @Update("update t_scenic_product_ticket set \n" +
            "supplier_ticket_number =null, \n" +
            "department_id=null,\n" +
            "department_name=null,\n" +
            "saler_id=null,\n" +
            "saler_name=null,\n" +
            "sale_number=null,\n" +
            "`status`=1,\n" +
            "sold_time=null where id in (${ids})\n" +
            " ")
    Integer backTicket(@Param("ids") String ids);

    @Select("<script> SELECT * from t_scenic_product_ticket  \n" +
            "where  product_id =#{productId}   </script>")
    List<ScenicProductTicket> queryByProductId(@Param("productId")Long productId);

}
